package com.gxa.ssm340.controller;

import com.gxa.ssm340.common.PageDTO;
import com.gxa.ssm340.common.R;
import com.gxa.ssm340.entity.pojo.Brand;
import com.gxa.ssm340.entity.vo.BrandVO;
import com.gxa.ssm340.service.BrandService;
import com.gxa.ssm340.service.BrandsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 叶骏
 * @description: TODO
 * @date 2023-10-23 18:28:48
 * @version: 1.0
 */
@RestController
@ApiOperation(value = "BrandController",tags = "品牌管理接口")
@RequestMapping("/brand")
public class BrandsController {
    @Autowired
    private BrandsService brandService;

    @ApiOperation("品牌管理列表")
    @RequestMapping("/list")
    public R getAll(){
        final List<Brand> all = brandService.getAll();
        return R.success(all);
    }

    @RequestMapping("/getList")
    public R getAlla(PageDTO pageDTO){
        final List<Brand> byPage = brandService.getByPage(pageDTO);
        final Integer count = brandService.count();
        final BrandVO brandVO = new BrandVO();
        brandVO.setCount(count);
        brandVO.setLists(byPage);
        return R.success(brandVO);
    }

    @ApiOperation("品牌添加")
    @RequestMapping("/add")
    public R add(@RequestBody Brand brand){
        final Integer add = brandService.add(brand);
        return R.success();
    }

    @ApiOperation("品牌删除")
    @RequestMapping("/delete")
    public R delete(Integer id){
        final Integer delete = brandService.delete(id);
        return R.success();
    }
}
